﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Microsoft.Data.Caching;

namespace MDCAdminTool
{
    public class CacheRegion : CacheEntityBase
    {
        #region MyRegion
        public string Role { get; set; }
        public int PortNo { get; set; }
        public bool EvictionOn { get; set; }
        public CacheRegionStats CacheRegionStats { get; set; }
        public Collection<DataCacheItemVersion> CacheItems { get; set; } 
        #endregion

        public CacheRegion(string region, string role , int port, MdcCache cache) : this( region , false , cache)
        {
            Role   = role;
            PortNo = port;
        }
        public CacheRegion( string region , bool evictionOn , MdcCache cache )
        {
            Name       = region;
            Parent     = cache;
            EvictionOn = evictionOn;

            LoadChildren();
        }


        public override string ToString()
        {
            return Name;
        }

        public override void LoadChildren()
        {
            //try
            //{
            //    Log( "DataCliet.GetObjectsInRegion(" + Name + ")" );
            //    var dc = CacheClientFactory.GetCache( CacheName );
            //    if ( dc == null ) return;

            //    var r =  dc.GetObjectsInRegion( Name );
            //    var result = new Collection<DataCacheItemVersion>();
            //    if ( r != null )
            //    {
            //        foreach (var item in r)
            //        {
            //            DataCacheItemVersion version;
            //            dc.Get(item.Key, out version);
            //            if (version != null)
            //                result.Add(version);
            //        }
            //        CacheItems = result;
            //    }
            //}
            //catch ( Exception ex )
            //{
            //    Log( new PowerShellCommand { CommandName = ex.Message } );
            //}
            
        }

        #region ICacheCommand Not Implemented
        public override void Start()
        {
            throw new NotImplementedException();
        }
        public override void Stop()
        {
            throw new NotImplementedException();
        }

        public override void Add(CacheEntityBase item)
        {
            throw new NotImplementedException();
        }
        public override void Remove( CacheEntityBase item )
        {
            throw new NotImplementedException();
        }

        public override CacheStats LoadStatistics()
        {
            throw new NotImplementedException();
        }
        public override void LoadConfig()
        {
            throw new NotImplementedException();
        }
        public override void SaveConfig()
        {
            throw new NotImplementedException();
        }
        #endregion
    }
}
